package com.base.cn.platform.os.controller.mobile.op.article;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.common.utils.count.PageFrom;
import com.base.cn.platform.os.common.utils.count.PageKeyUtils;
import com.base.cn.platform.os.service.manage.count.PageViewCountService;
import com.base.cn.platform.os.service.manage.op.article.OpArticleService;
import com.base.cn.platform.os.service.manage.op.article.OpArticleTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * H5资讯Controller
 *
 * @author xyw
 * @create 2018-10-25-11:17
 */
@Controller
@RequestMapping("/mobile/article")
public class MobileArticleController extends MobileBaseController {
@Autowired
private OpArticleService opArticleService;
@Autowired
private OpArticleTypeService opArticleTypeService;
    @Autowired
    private PageViewCountService pageViewCountService;

    /**
     * 加载新闻资讯
     * @param
     * @return
     */
    @RequestMapping("/opArticleList")
    public String opArticleList(Model model){
        Map<String, Object> params = new HashMap<>();
        params.put("status",1);

        List<Map<String, Object>> articleType = opArticleTypeService.queryAllArticleType(params);
        pageViewCountService.addPageCount(PageKeyUtils.CMS_INDEX, PageFrom.PAGE_FROM_MOBILE);

        model.addAttribute("dataMap",articleType);
        return resultPage("/op/article/op-article-list");
    }

    /**
     * Ajax加载新闻资讯
     * @param model
     * @param
     * @param article 资讯搜索条件
     * @return
     */
    @RequestMapping("/ajaxOpArticleList")
    public String ajaxOpArticleList(Model model,
                                     @RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
                                     @RequestBody Map<String, Object> article){
        article.put("status",0);
        article.put("releaseStatus",2);
        article.put("order",2);
        Map<String, Object> articleList = opArticleService.queryArticleList(currentPage,article);
        model.addAttribute("dataMap",articleList);
        return resultPage("/op/article/ajax-op-article-list");
    }

    /**
     * 新闻资讯详情
     * @param
     * @param articleId  资讯Id
     * @return
     */
    @RequestMapping("/articleInfoById")
    public String articleInfoById(Model model,
                                  @RequestParam("articleId") BigDecimal articleId){
        Map<String, Object> article = opArticleService.findArticleById(articleId, true, 5);
        model.addAttribute("article",article);
        return resultPage("/op/article/op-article-info");

    }
}
